package com.yaozheng.vocationaltraining.fragment;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.bean.BaoXianBean;
import com.yaozheng.vocationaltraining.bean.CarDetailBean;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

/**
 * Created by moon on 2017/11/21.
 */

@EFragment(R.layout.activity_shangyebaoxian)
public class ShangYeBaoXianFragment extends BaseFragment {

    @ViewById
    TextView headTitleText;

//    public CarDetailBean getCarDetailBean() {
//        return carDetailBean;
//    }
//
//    public void setCarDetailBean(CarDetailBean carDetailBean) {
//        this.carDetailBean = carDetailBean;
//    }
//
//    CarDetailBean carDetailBean;


    @ViewById
    LinearLayout disanzhezerenxian_layout;
    @ViewById
    CheckBox disanzhezerenxian_checkbox;
    @ViewById
    TextView disanzhezerenxian_value_textview;
    @ViewById
    TextView disanzhezerenxian_key_textview;

    @ViewById
    CheckBox cheliangsunshi_checkbox;
    @ViewById
    TextView cheliangsunshi_value_textview;

    @ViewById
    CheckBox quanchedaoqiang_checkbox;
    @ViewById
    TextView quanchedaoqiang_value_textview;

    @ViewById
    LinearLayout bolidanduposui_layout;
    @ViewById
    CheckBox bolidanduposui_checkbox;
    @ViewById
    TextView bolidanduposui_key_textview;
    @ViewById
    TextView bolidanduposui_value_textview;

    @ViewById
    CheckBox ziransunshi_checkbox;
    @ViewById
    TextView ziransunshi_value_textview;

    @ViewById
    CheckBox bujimianpei_checkbox;
    @ViewById
    TextView bujimianpei_value_textview;

    @ViewById
    CheckBox wuguozeren_checkbox;
    @ViewById
    TextView wuguozeren_value_textview;

    @ViewById
    CheckBox cheshangrenyuanzeren_checkbox;
    @ViewById
    TextView cheshangrenyuanzeren_value_textview;

    @ViewById
    LinearLayout cheshenghuaheng_layout;
    @ViewById
    CheckBox cheshenghuaheng_checkbox;
    @ViewById
    TextView cheshenghuaheng_key_textview;
    @ViewById
    TextView cheshenghuaheng_value_textview;

    @ViewById
    CheckBox sheshui_checkbox;
    @ViewById
    TextView sheshui_value_textview;

    public HomeActivity getHomeActivity() {
        return (HomeActivity) getActivity();
    }

    @AfterViews
    public void initView() {
        headTitleText.setText("商业保险");


        for(BaoXianBean bean : PriceFragment.carDetailBean.getDisanzhezerenxian()){
            if(bean.getDefaultStatus().equals("1")){
                disanzhezerenxian_value_textview.setText(bean.getKey());
                disanzhezerenxian_key_textview.setText((int)bean.getValue()+"");
            }
        }
        cheliangsunshi_value_textview.setText(PriceFragment.carDetailBean.getCheliangshunshixian()+"");
        quanchedaoqiang_value_textview.setText(PriceFragment.carDetailBean.getQuanchedaoqiangxian()+"");
        for(BaoXianBean bean : PriceFragment.carDetailBean.getBolidanduposuixian()){
            if(bean.getDefaultStatus().equals("1")){
                bolidanduposui_value_textview.setText(Math.round(bean.getValue()*PriceFragment.carDetailBean.getPrice() * 10000)+"");
                bolidanduposui_key_textview.setText(bean.getKey()+"");
            }
        }
        ziransunshi_value_textview.setText(PriceFragment.carDetailBean.getZiransunshixian()+"");
        bujimianpei_value_textview.setText(PriceFragment.carDetailBean.getBujimianpeiteyuexian()+"");
        wuguozeren_value_textview.setText(PriceFragment.carDetailBean.getWuguozerenxian()+"");
        cheshangrenyuanzeren_value_textview.setText(PriceFragment.carDetailBean.getCheshangrenyuanzerenxian()+"");
        for(BaoXianBean bean : PriceFragment.carDetailBean.getCheshenhuahenxian()){
            if(bean.getDefaultStatus().equals("1")){
                cheshenghuaheng_value_textview.setText((int)bean.getValue()+"");
                cheshenghuaheng_key_textview.setText(bean.getKey()+"");
            }
        }
        sheshui_value_textview.setText(PriceFragment.carDetailBean.getSheshuixian()+"");



        disanzhezerenxian_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (!b){
                    bujimianpei_checkbox.setChecked(false);
                    wuguozeren_checkbox.setChecked(false);
                    bujimianpei_checkbox.setEnabled(false);
                    wuguozeren_checkbox.setEnabled(false);
                    bujimianpei_value_textview.setVisibility(View.INVISIBLE);
                    wuguozeren_value_textview.setVisibility(View.INVISIBLE);

                    disanzhezerenxian_key_textview.setVisibility(View.INVISIBLE);
                    disanzhezerenxian_value_textview.setVisibility(View.GONE);

                    PriceFragment.carDetailBean.setHas_disanzhezerenxian(false);
                }else {
                    bujimianpei_checkbox.setEnabled(cheliangsunshi_checkbox.isChecked());
                    wuguozeren_checkbox.setEnabled(true);

                    disanzhezerenxian_key_textview.setVisibility(View.VISIBLE);
                    disanzhezerenxian_value_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_disanzhezerenxian(true);
                }
            }
        });

        cheliangsunshi_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (!b){
                    quanchedaoqiang_checkbox.setChecked(false);
                    bujimianpei_checkbox.setChecked(false);
                    cheshenghuaheng_checkbox.setChecked(false);

                    quanchedaoqiang_checkbox.setEnabled(false);
                    bujimianpei_checkbox.setEnabled(false);
                    cheshenghuaheng_checkbox.setEnabled(false);

                    quanchedaoqiang_value_textview.setVisibility(View.INVISIBLE);
                    bujimianpei_value_textview.setVisibility(View.INVISIBLE);
                    cheshenghuaheng_key_textview.setVisibility(View.INVISIBLE);

                    cheliangsunshi_value_textview.setVisibility(View.INVISIBLE);

                    PriceFragment.carDetailBean.setHas_cheliangshunshixian(false);
                }else{
                    quanchedaoqiang_checkbox.setEnabled(true);
                    bujimianpei_checkbox.setEnabled(disanzhezerenxian_checkbox.isChecked());
                    cheshenghuaheng_checkbox.setEnabled(true);

                    cheliangsunshi_value_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_cheliangshunshixian(true);
                }
            }
        });

        quanchedaoqiang_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    quanchedaoqiang_value_textview.setVisibility(View.VISIBLE);
                    PriceFragment.carDetailBean.setHas_quanchedaoqiangxian(true);
                }else {
                    quanchedaoqiang_value_textview.setVisibility(View.INVISIBLE);
                    PriceFragment.carDetailBean.setHas_quanchedaoqiangxian(false);
                }
            }
        });

        bolidanduposui_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    bolidanduposui_value_textview.setVisibility(View.VISIBLE);
                    bolidanduposui_key_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_bolidanduposuixian(true);
                }else {
                    bolidanduposui_value_textview.setVisibility(View.INVISIBLE);
                    bolidanduposui_key_textview.setVisibility(View.GONE);

                    PriceFragment.carDetailBean.setHas_bolidanduposuixian(false);
                }
            }
        });

        ziransunshi_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    ziransunshi_value_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_ziransunshixian(true);
                }else {
                    ziransunshi_value_textview.setVisibility(View.INVISIBLE);

                    PriceFragment.carDetailBean.setHas_ziransunshixian(false);
                }
            }
        });

        bujimianpei_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    bujimianpei_value_textview.setVisibility(View.VISIBLE);
                    PriceFragment.carDetailBean.setHas_bujimianpeiteyuexian(true);
                }else {
                    PriceFragment.carDetailBean.setHas_bujimianpeiteyuexian(false);
                }
            }
        });

        wuguozeren_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    wuguozeren_value_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_wuguozerenxian(true);
                }else {
                    wuguozeren_value_textview.setVisibility(View.INVISIBLE);

                    PriceFragment.carDetailBean.setHas_wuguozerenxian(false);
                }
            }
        });

        cheshangrenyuanzeren_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    cheshangrenyuanzeren_value_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_cheshangrenyuanzerenxian(true);
                }else {
                    cheshangrenyuanzeren_value_textview.setVisibility(View.INVISIBLE);

                    PriceFragment.carDetailBean.setHas_cheshangrenyuanzerenxian(false);
                }
            }
        });

        cheshenghuaheng_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    cheshenghuaheng_value_textview.setVisibility(View.VISIBLE);
                    cheshenghuaheng_key_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_cheshenhuahenxian(true);
                }else {
                    cheshenghuaheng_value_textview.setVisibility(View.INVISIBLE);
                    cheshenghuaheng_key_textview.setVisibility(View.GONE);

                    PriceFragment.carDetailBean.setHas_cheshenhuahenxian(false);
                }
            }
        });

        sheshui_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b){
                    sheshui_value_textview.setVisibility(View.VISIBLE);

                    PriceFragment.carDetailBean.setHas_sheshuixian(true);
                }else {
                    sheshui_value_textview.setVisibility(View.INVISIBLE);

                    PriceFragment.carDetailBean.setHas_sheshuixian(false);
                }
            }
        });

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.onDetach();
    }

    @Click({R.id.disanzhezerenxian_layout})
    public void disanzhezerenxianLayoutClick(View view) {
        getHomeActivity().openDiSanZheZeRenXianFragment(PriceFragment.carDetailBean);
    }

    @Click({R.id.bolidanduposui_layout})
    public void bolidanduposuiLayoutClick(View view) {
        getHomeActivity().openBoLiDanDuPoSuiXianFragment(PriceFragment.carDetailBean);
    }

    @Click({R.id.cheshenghuaheng_layout})
    public void cheshenghuahengLayoutClick(View view) {
        getHomeActivity().openCheShengHuaHengXianFragment(PriceFragment.carDetailBean);
    }




}
